package com.zhaopin.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author yin.peide
 * @date 2021-06-22 18:05
 */
public class FutureTaskTest {

    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<>(
                () -> {
                    int i = 1;
                    Thread.sleep(1000);
                    return i;
                });

        new Thread(futureTask).start();

        try {
            System.out.println(futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
